package com.youlai.boot.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.system.model.form.SysDianciListForm;
import com.youlai.boot.system.model.query.SysDianciListQuery;
import com.youlai.boot.system.model.vo.SysDianciListVO;
import com.youlai.boot.system.service.SysDianciListService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 电池列表前端控制层
 *
 * @author liwenbing
 * @since 2025-04-09 12:31
 */
@Tag(name = "电池列表接口")
@RestController
@RequestMapping("/api/v1/sysDianciLists")
@RequiredArgsConstructor
public class SysDianciListController {

    private final SysDianciListService sysDianciListService;

    @Operation(summary = "电池列表分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:sysDianciList:query')")
    public PageResult<SysDianciListVO> getSysDianciListPage(SysDianciListQuery queryParams) {
        IPage<SysDianciListVO> result = sysDianciListService.getSysDianciListPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增电池列表")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:sysDianciList:add')")
    public Result<Void> saveSysDianciList(@RequestBody @Valid SysDianciListForm formData) {
        boolean result = sysDianciListService.saveSysDianciList(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取电池列表表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:sysDianciList:edit')")
    public Result<SysDianciListForm> getSysDianciListForm(
            @Parameter(description = "电池列表ID") @PathVariable Long id
    ) {
        SysDianciListForm formData = sysDianciListService.getSysDianciListFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改电池列表")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:sysDianciList:edit')")
    public Result<Void> updateSysDianciList(
            @Parameter(description = "电池列表ID") @PathVariable Long id,
            @RequestBody @Validated SysDianciListForm formData
    ) {
        boolean result = sysDianciListService.updateSysDianciList(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除电池列表")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:sysDianciList:delete')")
    public Result<Void> deleteSysDianciLists(
            @Parameter(description = "电池列表ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = sysDianciListService.deleteSysDianciLists(ids);
        return Result.judge(result);
    }
}
